package com.chixing.day12_date_factory;


import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

public class DateDemo {
    public static void main(String[] args) {

       LocalDateTime dateTime1=  DateUtil.stringToLocalDateTime("2022/12/23 10:30:30");
        System.out.println(dateTime1);  // 2022-12-23T10:30:30

        LocalDate dateTime2 =  DateUtil.stringToLocalDate("2022/12/23");
        System.out.println(dateTime2);  // 2022-12-23

        String s1 = DateUtil.localDateTimeToString(dateTime1);
        System.out.println(s1);  //2022/12/23 10:30:30

        String s2 = DateUtil.localDateToString(dateTime2);
        System.out.println(s2); //2022/12/23


//        1. 获得当前时间
        LocalDateTime dateTime = LocalDateTime.now();

//        2. 获得2天以后的日期
        dateTime.plusDays(2);

//        3. 获得3天前的日期
        dateTime.minusDays(3);

//        4. 将字符串"2022/7/21 19:30" 转换成日期对象


//        5. 比较两天日期对象date  相差的天数
        LocalDateTime dateTime11 =  LocalDateTime.of(2022,8,1,9,30,30);
        LocalDateTime dateTime12 =  LocalDateTime.of(2022,8,5,9,30,30);
        long days = dateTime12.toLocalDate().toEpochDay()  - dateTime11.toLocalDate().toEpochDay();
        System.out.println(days);

    }
}
